package jmine.tec.services.utils.replace.transformation;

import jmine.tec.services.utils.replace.api.ServiceBlock;
import jmine.tec.services.utils.replace.api.ServiceRow;

public class RenameServiceTransformation extends AbstractTransformation {

    private final String newAction;

    private final String newName;

    public RenameServiceTransformation(String action, String name, String newAction, String newName) {
        super(action, name);
        this.newAction = newAction;
        this.newName = newName;
    }

    public void apply(ServiceBlock block) {
        for (ServiceRow row : block.getServices()) {
            if (this.matches(row)) {
                row.setAction(this.newAction);
                row.setName(this.newName);
            }
        }
    }

    @Override
    public String toString() {
        return String.format("RenameService: %s.%s -> %s.%s", this.action, this.name, this.newAction, this.newName);
    }
}
